<template>
  <el-collapse-item name="handleHistory">
    <template slot="title">
      <PartitionTitle title="历史处理信息"></PartitionTitle>
    </template>

    <el-card class="box-card" v-for='item in handleList' :key='item.id'>
      <div slot="header" class="clearfix">
        <span class="handleTime">{{item.handleTime}}</span>
        <span>{{item.handleName}}</span>
      </div>

      <el-descriptions :column="1">
        <el-descriptions-item label="是否为本机台异常" v-if="item.abnormalItselfVal">{{item.abnormalItselfVal}}</el-descriptions-item>
        <el-descriptions-item label="异常原因" v-if="item.abnormalReason">{{item.abnormalReason}}</el-descriptions-item>
        <el-descriptions-item label="本次处理方法" v-if="item.handleDes && item.handleType != 3">{{item.handleDes}}</el-descriptions-item>
        <el-descriptions-item label="附件" v-if='item.handleType != 3'>
          <div class="text-value" v-if="item.files && item.files.length">
            <el-link type="primary"
              v-for="file in item.files"
              :key='file.id'
              :underline="false"
              @click="preview(file)">
                {{file.fileName}}
            </el-link>
          </div>
          <div v-else>-</div>
        </el-descriptions-item>
        <el-descriptions-item label="转办至" v-if="item.processedName">{{item.processedName}}</el-descriptions-item>
        <el-descriptions-item label="备注" v-if="item.handleDes && (item.handleType == 3)">{{item.handleDes}}</el-descriptions-item>
      </el-descriptions>
    </el-card>
  </el-collapse-item>
</template>
<script>
  import {handleMap} from "../enum.js"
  import axios from 'axios'
  import { getToken } from '@/utils/auth'
  import service from "@//utils/request";
  import { GEN_SERVER } from '@/config/baseUrl'
  import { downloadFile } from '@/utils/file'
  import { parseTime } from '@/utils/eam'
export default {
  props:{
    recordsList:{
      type:Array,
      default:()=>[]
    },
    abnormalData:{
      type:Object,
      default:()=>{}
    }
  },
  data() {
    return {
      handleList:[],
      handleMap
    };
  },
  methods:{
    preview(item){
      axios({
        baseURL:service.baseURL + GEN_SERVER['form-server'],
        url:'/refine/report/byte/down',
        method:"get",
        params:{id:item.id},
        headers: {Authorization:'Bearer ' + getToken()},
        responseType: 'blob'
      }).then(res => {
        let count = item.fileName.lastIndexOf(".");
        let fileName = item.fileName.slice(0,count);
        let suffix = item.fileName.slice(count);
        downloadFile(res.data,`${fileName}${parseTime(new Date(), '{y}{m}{d}')}${suffix}`)
        this.saveloading = false
      }).catch(() => {
        this.msgError("操作失败")
        this.saveloading = false
      })
    }
  },

  watch:{
    recordsList:{
      handler(list){
        if(list?.length){
          this.handleList = list.filter(ele => ele.handleType != 1)
        }
      },
      deep: true,
      immediate: true
    }
  }
};
</script>
<style lang="scss" scoped>
.box-card{
  .clearfix{
    display:flex;
    justify-content: space-between;
    align-items: center;
    color: #F59A23;
    font-weight: 600;
    .handleTime{
      flex:1
    }
  }
  .text-value{
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
}
.box-card:not(:last-child){
  margin-bottom: 10px;
}
</style>
